<?php
	class cache {
	   protected $dir;
       
	   public function __construct($dir) {
            if(is_dir($dir)) {
                $this->dir = $dir;
            } else {
                throw new exception('Cache folder does not exsist');
            }
       }
       
       public function isFile($file) {
        if(file_exists($this->dir.$file)) {
            return true;
        } else {
            return false;
        }
       }
       
       public function get($file) {
        $data = file_get_contents($this->dir.$file);
        $ar = @unserialize($data);
        if(time() > $ar[0]) {
            @unlink($this->dir.$file);
        }
        return $ar[1];
       }
       
       public function saveFile($file, $data, $time = 600) {
        if(is_array($data)) {
            $data = serialize(array(time()+$time, $data));
        }
        $handle = fopen($this->dir.$file, 'w');
        $result = fwrite($handle, $data);
        fclose($handle);
       }
       
	}
?>